# 作者: 菅世博
# 2025年02月20日11时10分25秒
# 512326042@qq.com


class Person:
    def __init__(self, name, age, weight):
        """
        类的构造函数
        :param name:
        :param age:
        :param weight:
        """
        self.name = name
        self.age = age
        self.weight = weight

    def run(self):
        """
        跑步方法
        :return:
        """
        self.weight -= 0.5
        print(f"{self.name}跑步了,体重减少了0.5kg{self.weight}")

    def eat(self):
        """
        吃饭方法
        :return:
        """
        pass
        self.weight += 1
        print(f"{self.name}吃饭了,体重增加了1kg{self.weight}")

    def __str__(self):
        return f'{self.name}现在的体重是{self.weight}kg'


# elephant = Person("大象", 20, 50)  # 实例化对象
# elephant.run()  # 调用对象的方法
# elephant.eat()
# elephant.eat()
# print(elephant)
class HouseItem:
    def __init__(self, name, area):
        """
        家具类
        :param name: # 家具名称
        :param area: # 家具占地面积
        """
        self.name = name
        self.area = area

    def __str__(self):
        return f'{self.name}占地{self.area}平方米'


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type  # 房屋类型
        self.area = area  # 房屋面积
        self.free_area = area  # 剩余面积
        self.item_list = []  # 家具列表

    def add_item(self, item: HouseItem): # 冒号后面的是类型注解
        print(f'要添加{item}')
        if self.free_area >= item.area:
            self.item_list.append(item.name)
            self.free_area -= item.area
        else:
            print('房间面积不足,无法添加家具')

    def __str__(self):
        return f'房屋类型:{self.house_type}\n房屋面积:{self.area}\n剩余面积:{self.free_area}\n家具列表:{self.item_list}'




#1、创建家具
bed = HouseItem("席梦思", 4)
chest = HouseItem("衣柜", 2)
table = HouseItem("餐桌", 1.5)
# print(bed)
# print(chest)
# print(table)
house = House("两室一厅", 60)
print(house)
house.add_item(bed)
